﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;

namespace System.ComponentModel.Composition
{
    public static class CompositionIssueId
    {
        // Generally these issue types should map 1:1 to a string resource and the enum below
        public static readonly string ExceptionDuringImportCompletedCallback = CreateCMIssueId(CMIssueType.ExceptionDuringGettingOfExport);
        public static readonly string ImportCollectionFailedCollectionNull = CreateCMIssueId(CMIssueType.ImportCollectionFailedCollectionNull);
        public static readonly string ImportCollectionFailedCollectionNotWritable = CreateCMIssueId(CMIssueType.ImportCollectionFailedCollectionNotWritable);
        public static readonly string ImportSingleValueFailedNotWritable = CreateCMIssueId(CMIssueType.ImportSingleValueFailedNotWritable);
        public static readonly string CardinalityMismatch = CreateCMIssueId(CMIssueType.CardinalityMismatch);
        public static readonly string TypeMismatchBetweenImportAndExport = CreateCMIssueId(CMIssueType.TypeMismatchBetweenImportAndExport);
        public static readonly string ExceptionDuringSettingOfImport = CreateCMIssueId(CMIssueType.ExceptionDuringSettingOfImport);
        public static readonly string ExceptionDuringGettingOfExport = CreateCMIssueId(CMIssueType.ExceptionDuringGettingOfExport);
        public static readonly string InvalidExportMetadata = CreateCMIssueId(CMIssueType.InvalidExportMetadata);
        public static readonly string RequiredMetadataNotFound = CreateCMIssueId(CMIssueType.RequiredMetadataNotFound);
        public static readonly string ComposeTookTooManyIterations = CreateCMIssueId(CMIssueType.ComposeTookTooManyIterations);
        public static readonly string ExceptionDuringComponentActivation = CreateCMIssueId(CMIssueType.ExceptionDuringComponentActivation);
        public static readonly string NoSelectedConstructor = CreateCMIssueId(CMIssueType.NoSelectedConstructor);
        public static readonly string ImportNotSetOnPart = CreateCMIssueId(CMIssueType.ImportNotSetOnPart);
        public static readonly string ImportCycle = CreateCMIssueId(CMIssueType.ImportCycle);
        public static readonly string AdapterCannotAdaptFromAndToSameContract = CreateCMIssueId(CMIssueType.AdapterCannotAdaptFromAndToSameContract);
        public static readonly string AdapterContractMismatch = CreateCMIssueId(CMIssueType.AdapterContractMismatch);
        public static readonly string AdapterTypeMismatch = CreateCMIssueId(CMIssueType.AdapterTypeMismatch);
        public static readonly string ExceptionDuringAdapt = CreateCMIssueId(CMIssueType.ExceptionDuringAdapt);
        public static readonly string UnsupportedCachedValue = CreateCachingIssueId(CachingCMIssueType.UnsupportedCachedValue);

        // The enum is used here to ensure that we don't have any duplicate issue types.
        internal enum CMIssueType
        {
            ExceptionDuringImportCompletedCallback,
            ImportCollectionFailedCollectionNull,
            ImportCollectionFailedCollectionNotWritable,
            ImportSingleValueFailedNotWritable,
            CardinalityMismatch,
            TypeMismatchBetweenImportAndExport,
            ExceptionDuringSettingOfImport,
            ExceptionDuringGettingOfExport,
            InvalidExportMetadata,
            RequiredMetadataNotFound,
            ComposeTookTooManyIterations,
            ExceptionDuringComponentActivation,
            UnsupportedExportType,
            NoSelectedConstructor,
            ImportNotSetOnPart,
            ImportCycle,
            AdapterCannotAdaptFromAndToSameContract,
            AdapterContractMismatch,
            AdapterTypeMismatch,
            ExceptionDuringAdapt,
        }

        internal enum CachingCMIssueType
        {
            UnsupportedCachedValue
        }

        internal static string CreateCMIssueId(CMIssueType type)
        {
            return string.Format(System.Globalization.CultureInfo.InvariantCulture, "CM:{0}", type);
        }

        internal static string CreateCachingIssueId(CachingCMIssueType type)
        {
            return string.Format(System.Globalization.CultureInfo.InvariantCulture, "CM.Caching:{0}", type);
        }

    }

    internal static class CompositionIssueDetailKey
    {
        public static readonly string ContractName = "ContractName";
        public static readonly string ImportNode = "ImportNode";
        public static readonly string ComponentInstance = "ComponentInstance";
        public static readonly string ValueSetting = "ValueSetting";
    }
}
